package com.service.impl;

import com.dao.ResourceMapper;
import com.domain.Resource;
import com.domain.ResourceVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceMapper resourceMapper;

    /*
     * 资源分页及多条件查询
     * */
    @Override
    public PageInfo<Resource> findAllResource(ResourceVO resourceVO) {
        PageHelper.startPage(resourceVO.getCurrentPage(),resourceVO.getPageSize());
        List<Resource> resources = resourceMapper.findAllResource(resourceVO);
        return new PageInfo<>(resources);
    }
    /*
     * 添加资源
     * */
    @Override
    public void saveResource(Resource resource) {
        Date date = new Date();
        resource.setCreatedTime(date);
        resource.setUpdatedTime(date);

        resource.setCreatedBy("system");
        resource.setUpdatedBy("system");

        resourceMapper.saveResource(resource);
    }

    /*
     * 修改资源
     * */
    @Override
    public void updateResource(Resource resource) {
        resource.setUpdatedTime(new Date());
        resource.setUpdatedBy("system");

        resourceMapper.updateResource(resource);
    }
    /*
     * 删除资源
     * */
    @Override
    public void deleteResource(Integer id) {
        resourceMapper.deleteResource(id);
    }
}

